/**
 * 
 * The MIT License
 * 
 * Copyright (c) 2008 the original author or authors.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.googlecode.gchartjava;

import static com.googlecode.gchartjava.Color.*;
import static com.googlecode.gchartjava.ArraysUtil.asUnmodifiableList;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.googlecode.gchartjava.AxisStyle.AlignmentEnum;

/**
 * 
 * @author Julien Chastang (julien.c.chastang at gmail dot com)
 */
public class BarChartExample {
	
	@Test
	public void example1(){
		//Defining data series.
		BarChartDataSeries team1 = new BarChartDataSeries(new Data(55,43,60,82),BLUEVIOLET,"Team A");
		BarChartDataSeries team2 = new BarChartDataSeries(new Data(8,35,11,5),ORANGERED,"Team B");
		BarChartDataSeries team3 = new BarChartDataSeries(new Data(10,50,30,70),LIMEGREEN,"Team C");
		
		//Instantiating chart.
		BarChart chart = new BarChart(team1,team2,team3);

		//Defining axis info and styles
		AxisStyle axisStyle = new AxisStyle(BLACK,13,AlignmentEnum.CENTER);
		AxisInfo score = new AxisInfo(0,100,asUnmodifiableList(50f),"Score");
		score.setAxisStyle(axisStyle);
		AxisInfo year = new AxisInfo(0,100,asUnmodifiableList(50f),"Year");
		year.setAxisStyle(axisStyle);
		
		//Adding axis info to chart.
		chart.addXAxisInfo(new AxisInfo("2002", "2003", "2004", "2005"));
		chart.addYAxisInfo(new AxisInfo(0,100));
		chart.addYAxisInfo(score);
		chart.addXAxisInfo(year);
		
		chart.setSize(600, 450);
		chart.setSpaceBetweenGroupsOfBars(20);
		chart.setTitle("Team Scores",BLACK,16);
		chart.setGrid(new LineStyle(3,3,2), 10, 10);
		chart.setBackgroundFill(new SolidFill(ALICEBLUE));
		LinearGradientFill fill = new LinearGradientFill(0,LAVENDER,1);
		fill.addColorAndOffset(WHITE,0);
		chart.setAreaFill(fill);
		System.out.println(chart.createURLString());
		String expectedString = "http://chart.apis.google.com/chart?cht=bvg&chs=600x450&chxs=1,000000,13,0|3,000000,13,0&chts=000000,16&chxp=1,50.0|3,50.0&chf=bg,s,F0F8FF|c,lg,0,E6E6FA,1.0,FFFFFF,0.0&chdl=Team+A|Team+B|Team+C&chd=e:jMbhmZ0e,FIWZHCDN,GagATNsz&chtt=Team+Scores&chg=10,10,3,2&chbh=23,4,20&chxr=0,0,100|1,0,100|3,0,100&chxt=y,y,x,x&chco=8A2BE2,FF4500,32CD32&chxl=1:|Score|2:|2002|2003|2004|2005|3:|Year";
		assertEquals("Junit error", expectedString,chart.createURLString());
	}
	
	@Test
	public void example2(){
		//Defining data series.
		BarChartDataSeries team1 = new BarChartDataSeries(new Data(55,43,60,82),BLUEVIOLET,"Team A");
		BarChartDataSeries team2 = new BarChartDataSeries(new Data(8,35,11,5),ORANGERED,"Team B");
		BarChartDataSeries team3 = new BarChartDataSeries(new Data(10,50,30,70),LIMEGREEN,"Team C");
		BarChart chart = new BarChart(team1,team2,team3);

		//Defining axis info and styles
		AxisStyle axisStyle = new AxisStyle(BLACK,13,AlignmentEnum.CENTER);
		AxisInfo score = new AxisInfo(0,100,asUnmodifiableList(50f),"Score");
		score.setAxisStyle(axisStyle);
		AxisInfo year = new AxisInfo(0,100,asUnmodifiableList(50f),"Year");
		year.setAxisStyle(axisStyle);
		
		//Adding axis info to chart.
		chart.addXAxisInfo(new AxisInfo(0,100));
		chart.addXAxisInfo(score);
		chart.addYAxisInfo(new AxisInfo("2005","2004","2003","2002"));
		chart.addYAxisInfo(year);
		
		chart.setHorizontal(true);
		chart.setSize(600, 450);
		chart.setSpaceBetweenGroupsOfBars(20);
		chart.setTitle("Team Scores",BLACK,16);
		chart.setGrid(new LineStyle(3,3,2), 10, 10);
		chart.setBackgroundFill(new SolidFill(ALICEBLUE));
		LinearGradientFill fill = new LinearGradientFill(0,LAVENDER,1);
		fill.addColorAndOffset(WHITE,0);
		chart.setAreaFill(fill);
		System.out.println(chart.createURLString());
		String expectedString = "http://chart.apis.google.com/chart?cht=bhg&chs=600x450&chxs=1,000000,13,0|3,000000,13,0&chts=000000,16&chxp=1,50.0|3,50.0&chf=bg,s,F0F8FF|c,lg,0,E6E6FA,1.0,FFFFFF,0.0&chdl=Team+A|Team+B|Team+C&chd=e:jMbhmZ0e,FIWZHCDN,GagATNsz&chtt=Team+Scores&chg=10,10,3,2&chbh=23,4,20&chxr=1,0,100|2,0,100|3,0,100&chxt=y,y,x,x&chco=8A2BE2,FF4500,32CD32&chxl=0:|2005|2004|2003|2002|1:|Year|3:|Score";
		assertEquals("Junit error", expectedString,chart.createURLString());
	}
}
